#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,m,L,V;
ll T;
ll d[1000010],v[1000010],a[1000010];
ll w[100010];
ll o[1000100];
ll check(ll x,ll e)
{
	ll ans=sqrt(v[e]*v[e]+2*(w[x]-d[e])*a[e]);
	if(ans>V)
	    return 1;
	else
	    return 0;
}
void init()
{
	for(int i=1;i<=L;i++)
	    o[i]=0;
}
int main()
{
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>T;
	init();
	while(T--)
	{
		priority_queue<ll,vector<ll>,greater<ll> > q;
		cin>>n>>m>>L>>V;
		for(int i=1;i<=n;i++)
		    cin>>d[i]>>v[i]>>a[i];
		for(int i=1;i<=m;i++)
		    cin>>w[i];
		for(int i=1;i<=n;i++)
		{
			if(v[i]<=V&&a[i]<=0)
			    continue;
			if(v[i]>V&&a[i]>=0)
			{
				o[lower_bound(w+1,w+m+1,d[i])-w]++;
				continue;
			}
			if(v[i]<V&&a[i]>0)
			{
				if(sqrt(v[i]*v[i]+2*(w[m]-d[i])*a[i])<=V)
				    continue;
				ll l=1,r=m;
				ll mid;
				while(l<r)
				{
					mid=(l+r)>>1;
					if(check(mid,i))
						l=mid+1;
					else
						r=mid;
				}
				q.push(mid);
			    continue;
			}
			if(v[i]>V&&a[i]<0)
			{
				ll k=lower_bound(w+1,w+m+1,d[i])-w;
				if(sqrt(v[i]*v[i]+2*(w[k]-d[i])*a[i])<=V)
				    continue;
				ll l=1,r=m;
				ll mid;
				while(l<r)
				{
					mid=(l+r)>>1;
					if(check(mid,i))
						r=mid;
					else
						l=mid+1;
				}
				o[mid]++;
				continue;
			}
		}
		ll cnt=0;
		ll qw=0;
		ll ui=q.size();
		for(int i=1;i<=L;i++)
		{
			if(o[i])
			{
				cnt++;
				qw+=o[i];
				while(!q.empty()&&i>=q.top())
				    q.pop();
			}
		}
		cout<<qw+ui<<" ";
		cout<<m-cnt-q.size()<<endl;
		init();
	}
	return 0;
}
/*
1
5 5 15 3
0 3 0
12 4 0
1 1 4
5 5 -2
6 4 -4
2 5 8 9 15
*/
